package oop2.Task2;

/*
2：公司有公司名称，注册地址，电话，经营范围等属性，公司有很多员工（用Staff对象数组表示），公司有招聘员工方法，有输出员工信息方法，以及辞退员工方法(*选做)。
用oo的思想模拟

 */
public class Company {
    String name;
    String address;
    String phoneNum;
    String service;
    Staff[] staff = new Staff[100];
    int count = 0;

    public Company(String name, String address, String phoneNum, String service) {
        this.name = name;
        this.address = address;
        this.phoneNum = phoneNum;
        this.service = service;
    }

    public void showCompany() {
        System.out.println("公司的名字:" + name + ",业务是:" + service);
        System.out.println("注册地址:" + address + ",联系电话:" + phoneNum + "\n");
        ;
    }

    public boolean addStaff(Staff newStaff) {
//        System.out.println("新增员工");
        if (count >= staff.length) {
            System.out.println("人数已满");
            return false;
        }
        staff[count++] = newStaff;
        System.out.println("添加成功");
        return true;

    }

    //查看员工信息
    public void showStaff() {
        System.out.println(name + "公司员工信息为:");
        for (int i = 0; i < count; i++)
            staff[i].show();
    }

    //辞退员工
    public void dismiss(String sN0) {
        for (int i = 0; i < count; i++) {
            if (staff[i].sNo.equals(sN0)) {
                for (int j = i; j < count - 1; j++)
                    staff[j] = staff[j + 1];
                staff[--count] = null;
                System.out.println("辞退成功");
                return;
            }
        }
        System.out.println("未找到指定工号，辞退失败");
    }

    //统计公司员工人数
    public int getStaffNumber() {
        return count;
    }

    //查找薪水最高的员工
    public Staff findTopSalary() {
        if (count == 0)
            return null;
        Staff person = staff[0];
        for (int i = 1; i < count; i++) {
            if (person.salary < staff[i].salary) {
                person = staff[i];
            }
        }
        return person;
    }

    //实现薪水从高到低排序，冒泡排序,这样操作，每一轮最小的数在最后面依次冒出
    public void sortBySalDesc() {
        for (int i = 0; i < count - 1; i++) {
            for (int j = 0; j < count - 1 - i; j++) {
                if (staff[j].salary < staff[j + 1].salary) {
                    Staff person = staff[j];
                    staff[j] = staff[j + 1];
                    staff[j + 1] = person;
                }
            }
        }
    }

}
